﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0"><!-- InstanceBeginEditable name="doctitle" -->
<title>公告发布</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script> 
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
<script type="text/javascript" src="../js/ImageBrowsing.js"></script> 
	<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/ajaxfileupload.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script> 
	<script charset="utf-8" src="../js/kindeditor.js"></script>
	<script charset="utf-8" src="../js/lang/zh_CN.js"></script>
	<link rel="stylesheet" href="../css/default.css" />
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<style type="text/css">
	#imgSrc img{
    bottom: 0;
    font-size: 12px;
    font-weight: normal;
    height: 100px;
    position: absolute;
    right: 65px;
    vertical-align: bottom;
    width: 100px;}

</style>
<script type="text/javascript">
	var htmlStr=null;
$(function(){
	$(".hideDiv").each(function(){
		addMargin($(this));
	});

	$("#aunoType").click(function(){
		$("#yinyingCenter,#window1").show();
	})
	$.ajax({
		type : "get",
		async:false,
		datatype : "json",
		url : "../aunouncementType/find/aunouncementTypeList",
		success : function(data) {
			var rst = JSON.parse(data);
			if(IsEmpty(rst)){
				art.dialog({fixed:true, lock: true,content:"数据查询错误",icon:'error',ok:true});	
				return false;
				}
					$("#aunoTypeList tbody").empty()
					$("#searchType ").empty();
				if(rst.state==0){
					for ( var i = 0; i < rst.result.data.length; i++) {
						var typeId=getHtmlInt(getHeadIndexValue(i, rst, "id"));
						var typeName=getHtmlString(getHeadIndexValue(i, rst, "name"));
						var code=getHtmlString(getHeadIndexValue(i, rst, "code"));
						var htm1="<option value=''>所有</option><option value='"+typeId+"'>"+typeName+"</option>";
						$("#searchType ").append(htm1);
						var htm2="<td>"+typeName+"</td><td>"+code+"</td><td><input type=\"button\" value=\"选择\" onclick='chooseAunoType("+typeId+",$(this))' class=\"common_btn\"></td>"
						$("#aunoTypeList tbody").append("<tr></tr>")					
						$("#aunoTypeList tbody tr:last").append(htm2)
					}
					 }else if(rst.state==1){
							art.dialog({fixed:true, lock: true,content:"数据查询出错",icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}	
			
			
		}	
	});
	
	$("#editIndex_btn").click( function(){
		$("#window_changeff,#yinying").show();
		editor= KindEditor.create('#editIndex', {
			pasteType : 2,
			width:670,
			height:400
		});
		editor.html(htmlStr);
		addMargin($("#window_changeff"));		
	})
	browse('upload','imgSrc',75,51)
	$("input[type='file']").change(function(){
		$(this).prev().prev().val($(this).val())
	})
});
var pageCount=0;
var pageIndex=1;

function initTable(){
	var title=$("#searchTitle").val().replace(/\s/gi,'');
	var typeId=$("#searchType").val();
	var status=$("#searchStatus").val();
	//var param='title='+title+'&typeId='+typeId+"&status="+status;
	var param={'title':title,'typeId':typeId,'status':status}
	$.ajax({
		type : "get",
		async:false,
		data :param,
		datatype : "json",
		url : "../aunouncement/find/aunouncementList/" + pageIndex + "/10",
		success : function(data) {
			var rst = JSON.parse(data);
					if(IsEmpty(rst)){
						art.dialog({fixed:true, lock: true,content:"数据查询错误",icon:'error',ok:true});	
						return false;
						}
						if(rst.state==0){
							$("#funcMenuList tbody tr").remove();
							loadTable(rst);	
							if(rst.result.len > 0){
								 var shu = rst.result.len;
								 pageCount = Math.ceil(shu/10);
								 $("#NoResult").hide();
							}else{
								$("#NoResult").show();
								pageCount=0;

							}
							 	$("#sup").html("共"+rst.result.len+"条");	
							 $("#pager").pager({ pagenumber: pageIndex, pagecount: pageCount, buttonClickCallback: PageClick });

							 }else if(rst.state==1){
									art.dialog({fixed:true, lock: true,content:"数据查询出错",icon:'error',ok:true});	
						}else{
							checkStateShowErrorMsgAndDealResult(data);
						}			
					
					
		}	
	});
	
}

PageClick = function(pageclickednumber) {
   pageIndex=pageclickednumber;
   initTable();
}

function loadTable(json){
	$("#aunounceList tbody").empty()
	for ( var i = 0; i < json.result.data.length; i++) {
		var id=getHtmlInt(getHeadIndexValue(i, json, "id"));
		var typeId=getHtmlInt(getHeadIndexValue(i, json, "typeId"));
		var title=getHtmlString(getHeadIndexValue(i, json, "title"));
		var content=getHtmlString(getHeadIndexValue(i, json, "content"));
		var auditor=getHtmlString(getHeadIndexValue(i, json, "auditor"));
		var creatTime=getHtmlString(getHeadIndexValue(i, json, "creatTime"));
		var status=getHtmlString(getHeadIndexValue(i, json, "status"));
		var staName=getHtmlString(getHeadIndexValue(i, json, "staName"));
		var imageUrl=getHtmlString(getHeadIndexValue(i, json, "imageUrl"));
		var indexUrl=getHtmlString(getHeadIndexValue(i, json, "indexUrl"));
		var autyName=getHtmlString(getHeadIndexValue(i, json, "autyName"));
		var autyCode=getHtmlString(getHeadIndexValue(i, json, "autyCode"));
		
		$("#aunounceList tbody").append("<tr></tr>");
		var htm="<td id='auno_title_"+id+"'>"+title+"</td>";
		 htm+="<td id='auno_content_"+id+"'>"+content+"</td>";
		 htm+="<td id='auno_imageUrl_"+id+"' style=\"display: none;\">"+imageUrl+"</td>";
		 htm+="<td id='auno_indexUrl_"+id+"' style=\"display: none;\">"+indexUrl+"</td>";
		 htm+="<td id='auno_auditor_"+id+"'>"+auditor+"</td>";
		 htm+="<td id='auno_creatTime_"+id+"'>"+creatTime+"</td>";
		 htm+="<td id='auno_autyName_"+id+"'>"+autyName+"</td>";
		 htm+="<td id='auno_staName_"+id+"'>"+staName+"</td>";
		 htm+="<td><input type='hidden' id='auno_status_"+id+"' value='"+status+"'><input type='hidden' id='auno_typeId_"+id+"' value='"+typeId+"'> <input onclick='toUpdate("+id+")' class=\"common_btn\" type=\"button\" value=\"修改\"><br><input onclick='popPoint("+id+")' class=\"del\" type=\"button\" value=\"删除\"></td>"
		 $("#aunounceList tbody tr:last").append(htm);
		}
	
}

function toAdd(){
	retForm();
	$("#doflag").val(1);
	$("#yinying1,#mainMenu").show();
}
function toUpdate(id){
	retForm();
	$("#doflag").val(2);
	$("#updateId").val(id);
	var title=$("#auno_title_"+id).html();
	var indexUrl=$("#auno_indexUrl_"+id).html();
	var imageUrl=$("#auno_imageUrl_"+id).html();
	var autyName=$("#auno_autyName_"+id).html();
	var typeId=$("#auno_typeId_"+id).val();
	var status=$("#auno_status_"+id).val();
	var content=$("#auno_content_"+id).html();
	var auditor =$("#auno_auditor_"+id).html();
	$("#title").val(title);
	$("#indexUrl").val(indexUrl);
	$("#imgSrc img").attr("src",imageUrl)
	$("#imgName").val(imageUrl);
	$("#aunoType").val(autyName);
	$("#aunoTypeId").val(typeId);
	$("#auditor").val(auditor)
	$("#status").val(status);
	$("#content").val(content);
	$("#save_btn").val("保存修改")
	$.ajax({
		type : "get",
		async:false,
		datatype : "json",
		url : "../htmlUtils/find/htmlStr/" + id + "/announceIndex",
		success : function(data) {
			var rst = JSON.parse(data);
					if(IsEmpty(rst)){
						art.dialog({fixed:true, lock: true,content:"加载首页出错",icon:'error',ok:true});	
						return false;
						}
						if(rst.state==0){
							htmlStr=getHeadIndexValue(0, rst, "htmlStr");	
							 }else if(rst.state==1){
									art.dialog({fixed:true, lock: true,content:"加载首页出错",icon:'error',ok:true});	
						}else{
							checkStateShowErrorMsgAndDealResult(data);
						}		
		}	
	});
	$("#yinying1,#mainMenu").show();

}

function save(){
	var doflag=$("#doflag").val();
	if(doflag==1){
		addInfo();
	}else if(doflag==2){
		updateInfo()
	}else{
			art.dialog({fixed:true, lock: true,content:"页面错误",icon:'error',ok:true});	
		window.location.reload();
	}
}

function addInfo(){
	
	var title=$("#title").val().replace(/\s/gi,'');
	var aunoType=$("#aunoType").val();
	var status=$("#status").val();
	var content=$("#content").val();
	var autyId =$("#aunoTypeId").val();
	var auditor=$("#auditor").val()
	if(IsEmpty(autyId)){
		art.dialog({fixed:true, lock: true,content:"请选择类型",icon:'error',ok:true});	
		return false;
	}
	
	if(IsEmpty(title)){
		art.dialog({fixed:true, lock: true,content:"请填写标题",icon:'error',ok:true});	
		$("#title").focus();
		return false;
	}
	if(IsEmpty(htmlStr)){
		art.dialog({fixed:true, lock: true,content:"请编辑首页",icon:'error',ok:true});	
		return false;
	}
	
	var heads=new Array("autyId","title","content","status","auditor");
	var datas=new Array(autyId,title,content,status,auditor);
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "add" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}	
	
	$.post("../aunouncement/insert",{"data":jsonParserStr}, function(data) {
		var dt = JSON.parse(data);
		if(IsEmpty(dt)){
			art.dialog({fixed:true, lock: true,content:"添加数据出错",icon:'error',ok:true});	
			return false;
			}
			if(dt.state==0){
				var flag= addIndexHtml(getHeadIndexValue(0, dt, "id"));
				if(IsNotEmpty($("#upload").val())){
				uploadImage(getHeadIndexValue(0, dt, "id"),flag)
				}else{
					if(flag>0){
						$("#doflag").val(2);
						$("#updateId").val(id);
					art.dialog({fixed:true, lock: true,content:"首页生成出错,请重新编辑",icon:'error',ok:true});	
					}else{
						$("#yinying1,#mainMenu").hide();
						initTable();
						retForm();
						art.dialog({fixed:true, lock: true,content:"添加成功",icon:'succeed',ok:true});	
					}
				}
				
				}else if(dt.state==1){
				art.dialog({fixed:true, lock: true,content:"添加数据出错",icon:'error',ok:true});	
			}else{
				checkStateShowErrorMsgAndDealResult(data);
			}	
	});
}
function updateInfo(){
	var id=$("#updateId").val();
	if(IsEmpty(id)){
		art.dialog({fixed:true, lock: true,content:"页面出错",icon:'error',ok:true});	
		window.location.reload();
	}
	var title=$("#title").val().replace(/\s/gi,'');
	var aunoType=$("#aunoType").val();
	var status=$("#status").val();
	var content=$("#content").val();
	var autyId =$("#aunoTypeId").val();
	var auditor=$("#auditor").val()
	if(IsEmpty(autyId)){
		art.dialog({fixed:true, lock: true,content:"请选择类型",icon:'error',ok:true});	
		return false;
	}
	
	if(IsEmpty(title)){
		art.dialog({fixed:true, lock: true,content:"请填写标题",icon:'error',ok:true});	
		$("#title").focus();
		return false;
	}
	if(IsEmpty(htmlStr)){
		art.dialog({fixed:true, lock: true,content:"请编辑首页",icon:'error',ok:true});	
		return false;
	}
	
	var heads=new Array("autyId","title","content","status","auditor","id");
	var datas=new Array(autyId,title,content,status,auditor,id);
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "edit" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}	
	
	$.post("../aunouncement/edit",{"data":jsonParserStr}, function(data) {
		var dt = JSON.parse(data);	
		if(IsEmpty(dt)){
			art.dialog({fixed:true, lock: true,content:"修改出错",icon:'error',ok:true});	
			return false;
			}
			if(dt.state==0){
				var flag= addIndexHtml(id)
				if(IsEmpty($("#upload").val())){
					if(flag==0){
						$("#yinying1,#mainMenu").hide();
						initTable();
						retForm();
				art.dialog({fixed:true, lock: true,content:"修改成功",icon:'succeed',ok:true});	
					}else{
						$("#doflag").val(2);
						$("#updateId").val(id);
				art.dialog({fixed:true, lock: true,content:"首页生成出错,请重新编辑",icon:'error',ok:true});	
					}
					}else{
				uploadImage(id,flag)
				
				}
				
				}else if(dt.state==1){
					art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});	
			}else{
				checkStateShowErrorMsgAndDealResult(data);
			}
		
	});
}

function deleteInfo(id){
	
	if(IsNotEmpty(id)){

		$.post("../aunouncement/del",{"id":id}, function(data) {
			var dt = JSON.parse(data);
			if(IsEmpty(dt)){
				art.dialog({fixed:true, lock: true,content:"删除出错",icon:'error',ok:true});	
				return false;
				}
				if(dt.state==0){
					initTable()
					art.dialog({fixed:true, lock: true,content:"删除成功",icon:'succeed',ok:true});		
			}else if(dt.state==1){
					art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}
			
		});
	}
}
function uploadImage(id,flag){
	$.ajaxFileUpload({
		url :"../aunouncement/upload/images/aunouncement/"+id,
		secureuri : false,
		async:false,
		fileElementId : 'upload',
		dataType : 'json',
		success : function(data){
			if (data.state == 0) {
				if(flag==0){
					retForm();
					initTable();
					art.dialog({fixed:true, lock: true,content:"操作成功",icon:'succeed',ok:true});		
					$("#yinying1,#mainMenu").hide();
				}else{
					$("#updateId").val(id);
					$("#doflag").val(2);
					art.dialog({fixed:true, lock: true,content:"首页生成失败",icon:'error',ok:true});		
	
				}
			}else{
				$("#updateId").val(id);
				$("#doflag").val(2);
				if(flag==0){
					
				art.dialog({fixed:true, lock: true,content:"图片上传失败，请在修改页面重新编辑图片",icon:'error',ok:true});		
				}else{
					art.dialog({fixed:true, lock: true,content:"图片和首页保存失败",icon:'error',ok:true});		
				}
			}
		},
		error : function(data) {
			art.dialog({fixed:true, lock: true,content:"图片上传失败",icon:'error',ok:true});	
			return false;
		}
	});

	browse('upload','imgSrc',75,51)
}
function addIndexHtml(id){
	var indexHtml=htmlStr;
	var flag=0
	if(IsNotEmpty(indexHtml)){
		
		$.ajax({
			type : "post",
			async:false,
			data :{"htmlStr":indexHtml},
			datatype : "json",
			url : "../htmlUtils/upload/htmlAunouncementInit/"+id+"/announceIndex",
			success : function(data) {
				var rst = JSON.parse(data);
				if(rst.state==0){
				}else{
					flag=1
					art.dialog({fixed:true, lock: true,content:"首页生成失败",icon:'error',ok:true});	
				}		
			}	
		});
		
	}
	return flag;
}
function saveHtml(){
	if(IsEmpty(editor)){
		htmlStr="";
	}else{	
		htmlStr=editor.html();
	}
	editor.remove("#editIndex")
	var doflag=$("#doflag").val();
	if(doflag==1){		
		if(IsNotEmpty(htmlStr)){
			$("#indexUrl").val("已编辑");
		}else{
			$("#indexUrl").val("未编辑")
		}
		}
	$("#window_changeff,#yinying").hide();
	}
function cancelHtml(){
	editor.remove("#editIndex")
	var doflag=$("#doflag").val();
	if(doflag==1){		
		if(IsNotEmpty(htmlStr)){
			$("#indexUrl").val("已编辑");
		}else{
			$("#indexUrl").val("未编辑")
		}
		}
	$("#window_changeff,#yinying").hide();
}	
	
function retForm(){
	htmlStr=null;
	$("#title").val("");
	$("#upload").val("");
	$("#content").val("")
	$("#indexUrl").val("");
	$("#imgName").val("")
	$("#aunoType").val("")
	$("#imgSrc img").attr("src","../images/img_activities1.jpg");
	$("#doflag").val(1);
	$("#auditor").val("")
	$("#save_btn").val("添加")
}	

function chooseAunoType(id,obj){
	$("#aunoTypeId").val(id);
	$("#aunoType").val(obj.parents("tr").find("td").html())
	$("#yinyingCenter,#window1").hide();

}

function popPoint(id){
	art.dialog({fixed:true, lock: true,content:"确认删除该条数据？",icon:'question',ok: function(){ deleteInfo(id)},cancel:true});
	}

</script>


</head>

<body>
<!-- InstanceBeginEditable name="EditRegion3" --> 
<div id="yinying1"></div>
<div id="yinyingCenter"></div>
<div id="window_changeff" class="hideDiv setHTML" >
	<textarea id="editIndex" name="editIndex"></textarea>
	<div class="BottomBtn">
        <input type="button" value="确定" class="common_btn" onclick="saveHtml()" >
        <input type="button" value="取消" class="common_btn" style="background-color: red;" onclick="cancelHtml()" >
      </div>
</div>
<div class="hideDiv" id="window1" style="z-index:240;">
<div class="closeTop"><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
<table id="aunoTypeList" width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0">
    	<caption>公告类型列表      </caption>
    	<thead>
    	<tr>
    		<th width="10%">类型名称</th>
        	<th width="10%">类型编码</th>
        	<th width="15%">操作</th>
        </tr>
        </thead>
       	<tbody>
       		
       	</tbody>
    </table>
</div>
<div class="member_search publish WX hideDiv" id='mainMenu'>
<div class="closeTop"><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
       <form name="fm1" action="#" target="post">
       	<input type="hidden" id="updateId">
       	<input type="hidden" id="doflag" value="1">  
    <p><span>标题：</span>
      <input type="text" id="title" class="reset" >
    </p> 
    <p><span>首页：</span>
        <input type="text" id="indexUrl"  class="reset">
        <input type="button" class="btn"  value="编辑首页" id="editIndex_btn" style="font-size:12px;font-weight:normal;"></p> 
    <p>
    <p ><span>图片：</span>
        <input type="text" class="reset" id="imgName" readonly>
        <input type="button" class="btn" value="…">
        <input type="file" class="file reset" id="upload" name="upload">
       <span id="imgSrc"> <img  src="" ></span></p>
    <p><span>类型：</span>
    <input type="hidden" id="aunoTypeId" value="">
      <input type="text" readonly placeholder="请选择类型" id="aunoType">
    </p><p><span>状态：</span>
   		<select id="status"><option value="0">使用</option><option value="1">停用</option></select>
    </p>
    <p><span>创建人：</span>
        <input type="text" id="auditor" class="reset" >
    </p>
      <p><span>内容简介：</span>
        &nbsp;<textarea id="content" class="reset"></textarea>
      </p>
      <div class="BottomBtn">
        <input type="button"  value="立即提交" onclick="save()" id="save_btn">
      </div>
        </form>      
       </div>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">公告发布</div>
    <div class="member_search">
      <p>
        <span>标题：</span>
        <input type="text" id="searchTitle" class="absoluteTxt">
        <span>类型：</span>
        <select id="searchType" style="width:auto;"></select> 
        <label><span>状态：</span><select selected id="searchStatus" style="width:auto;"><option value="">全部</option><option value="0">正常</option><option value="1">非正常</option></select></label>
        <input class="btn" id="research" name="查询" type="button"  value="查询" onClick="initTable()" >
      </p>
      </div>
       <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="aunounceList">
    	<caption><strong>公告列表       <span id="sup">共0条</span></strong>  <input type="button" class="common_btn" value="增加" onclick="toAdd()"></caption>
    	<thead>
    	<tr>
    		<th width="10%">标题</th>
        	<th width="10%">简介</th>
        	<th width="11%">创建人</th>
        	<th width="10%">创建日期</th>
        	<th width="10%">类型</th>
        	<th width="5%">状态</th>
        	<th width="3%">操作</th>
        </tr>
        </thead>
        <tbody></tbody>
    </table>
   <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
showTab(2,1);
</script>
</body>
<!-- InstanceEnd -->
</html>
